﻿using DotNetCore.CAP.Transport;
using Microsoft.Extensions.Logging;

namespace CapHttp.Core;

public class HttpConsumerClientFactory : IConsumerClientFactory
{
    private readonly ILoggerFactory _loggerFactory;
    private readonly HttpConsumerMiddleware _middleware;

    public HttpConsumerClientFactory(HttpConsumerMiddleware middleware, ILoggerFactory loggerFactory)
    {
        _middleware = middleware;
        _loggerFactory = loggerFactory;
    }

    public IConsumerClient Create(string groupId)
    {
        var logger = _loggerFactory.CreateLogger<HttpConsumerClient>();
        logger.LogInformation("Creating consumer client for {groupName}", groupId);
        return new HttpConsumerClient(_middleware, groupId, logger);
    }
}